import Collapse from 'components/Markdown/Collapse'
import Warning from 'components/Markdown/Warning'

export const meta = {
  title: 'Prisma GraphQL API',
  position: 5
}

## Prisma GraphQL API

Every Prisma service exposes a GraphQL API with CRUD and realtime operations for the types defined in the service's datamodel. This API is called the **Prisma API**.

The GraphQL schema defining the types and operations of the Prisma API is referred to as the **Prisma GraphQL schema**. It is automatically generated by Prisma based on the [datamodel](knul).

<Warning>

The Prisma API is typically not consumed directly by a frontend/mobile application, but instead it's consumed through the [Prisma client](/prisma-client) in a web application server to implement a GraphQL or REST API and interface with the database. Consuming the Prisma API directly is equivalent to exposing your entire database to the frontend, without business logic or authorization capabilities which typically is not suitable for production applications.

</Warning>

There are still some use cases where it can be appropriate to consume the Prisma API directly from frontend/mobile apps:

- **Prototyping**: While you're still in the validation phase of an application, using the Prisma API directly notably speeds up your development. When going into production, it's recommended to use Prisma as the ORM-layer in your app.
- **Internal tooling & public APIs**: If your API doesn't have any requirements for access permissions, no business logic is required, it might be a valid option to expose the Prisma API directly to client applications.
- **Learning**: If you want to learn how GraphQL is consumed from the frontend (e.g. using Apollo Client), you can consume the Prisma API directly without the need to add an additional web server layer on top.

<Collapse title="Try out the Prisma API in a GrapQL Playground">

Click [**here**](https://eu1.prisma.sh/running-examples/hello-world/dev) to explore a Prisma API in a GraphQL Playground.

The Prisma API is based on the following [datamodel](knul):

```graphql
type Post {
  id: ID! @unique
  createdAt: DateTime!
  updatedAt: DateTime!
  isPublished: Boolean! @default(value: "false")
  title: String!
  text: String!
  author: User!
}

type User {
  id: ID! @unique
  email: String! @unique
  password: String!
  name: String!
  posts: [Post!]!
}
```

</Collapse>

This chapter explains everything you need to know about the Prisma API and how it can be used in various contexts.

| Page | Description |
| -- | --- |
| [**Using the Prisma API**](nms2) | Learn about various ways to consume the Prisma API using plain HTTP (e.g. `curl` and `fetch`). |
| [**Authentication**](ghd4) | Learn how to protect your Prisma API using the service secret. |
| [**Concepts**](vw4d) | Learn about the most important API concepts such as batching, Relay connections, transactions, cascading deletes, ... 
| [**Queries**](qwe1) | Learn about the auto-generated queries in the Prisma API. |
| [**Mutations**](qwe2) | Learn about the auto-generated mutations in the Prisma API. |
| [**Subscriptions**](qwe3) | Learn about the auto-generated subscriptions in the Prisma API. |
| [**Error Handling**](pdfv) | Learn how Prisma deals with errors in API requests. |